<?php

class Listener_Platform_Order extends Listener_Base
{
    public function handle($args)
    {
        $self       = new self();
        $self->args = $args;
        //判断队列是否开启,如果开启则把任务推送到队列
        if ($self->queue_status) {
            Queue::in('default', Listener_platform_Order::class, $args);
        } else {
            $self->perform();
        }
    }

    public function perform()
    {
        $order = $this->args['order'] ?? $this->args;

        $event_name = St_Functions::get_event_name($order['status']);
        file_put_contents(__DIR__."/test3.txt",var_export($order,true),FILE_APPEND);
        St_Log::write('平台交易明细', array('status' => $order['status']), "event/{$event_name}/log");
        switch ($order['status']) {
            case 2:
            case 5:
                $res = Model_Platform_Listener::order_listener($order['ordersn']);
                break;
            default:
                $res = [
                    'status' => false,
                    'msg'    => '订单状态错误，仅处理状态2、5的订单'
                ];
                break;
        }
        St_Log::write('平台交易明细', array('status' => $order['status'], 'ordersn' => $order['ordersn'], 'result' => $res), "event/{$event_name}/log");
    }

}